package cn.gotom.core.web.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import cn.gotom.core.web.Constants;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class SupportAction extends ActionSupport implements SessionAware, ApplicationAware, ServletResponseAware, ServletRequestAware
{

	private static final long serialVersionUID = 1L;
	protected final Logger log = Logger.getLogger(getClass());
	private Map<String, Object> session;
	private Map<String, Object> application;
	private String actionmessage;
	
	protected HttpServletResponse response;
	protected HttpServletRequest request;

	public String cancel()
	{
		return Constants.CANCEL;
	}

	private String task = null;

	public String getTask()
	{
		return task;
	}

	public void setTask(String value)
	{
		task = value;
	}

	private String token = null;

	public String getToken()
	{
		return token;
	}

	public void setToken(String value)
	{
		token = value;
	}

	private String host;

	public String getHost()
	{
		return host;
	}

	public void setHost(String value)
	{
		host = value;
	}

	@Override
	public void setApplication(Map<String, Object> arg0)
	{
		application = arg0;
	}

	@Override
	public void setSession(Map<String, Object> arg0)
	{
		session = arg0;
	}

	public Map<String, Object> getSession()
	{
		if (session == null)
		{
			ActionContext ctx = ActionContext.getContext();
			session = ctx.getSession();
		}
		return session;
	}

	public Map<String, Object> getApplication()
	{
		if (application == null)
		{
			ActionContext ctx = ActionContext.getContext();
			application = ctx.getApplication();
		}
		return application;
	}

	public String getActionmessage()
	{
		return actionmessage;
	}

	public void setActionmessage(String actionmessage)
	{
		this.actionmessage = actionmessage;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0)
	{
		request = arg0;
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0)
	{
		response = arg0;
	}
}
